import { createSSRApp } from 'vue'
import { createStore } from './store'
import App from './App.vue'
import { createRouter } from './router'
import Vue from 'vue'

export function createApp() {
  const app = createSSRApp(App)
  const router = createRouter()
  const store = createStore()
  app.use(router)
  app.use(store)

  app.mixin({
    beforeMount() {
      const { asyncData } = this.$options;
      if (asyncData) {
        // 将获取数据操作分配给 promise
        // 以便在组件中，我们可以在数据准备就绪后
        // 通过运⾏ `this.dataPromise.then(...)` 来执⾏其他任务
        this.dataPromise = asyncData({
          store: this.$store,
          route: this.$route,
        });
      }
    }
  })
  return { app, router, store }
}
